package com.threenewboard.controller;

import java.util.*;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import com.threenewboard.dao.*;
import com.threenewboard.entity.*;
import com.threenewboard.service.ResponseMessage;
import com.threenewboard.util.*;

import net.sf.json.JSONObject;

/**
 * @author sunbo@pgytesting.cn
 * @ClassName: ThreeNewBoardController
 * @Description: TODO(全部的controller层)
 * @date 2018年10月25日 上午10:52:15
 */

@Controller
@RequestMapping
public class ThreeNewBoardController {

    @Resource
    private UserDao userDao;
    @Resource
    private StockCodeInformationDao stockCodeDao;
    @Resource
    private CapitalFlowDao capitalFlowDao;
    @Resource
    private TransferInformationDao transferInformationDao;
    @Resource
    private StockTradingDao stockTradingDao;
    @Resource
    private BuyinformationDao buyinformationDao;
    @Resource
    private SellinformationDao sellinformationDao;
    @Resource
    private TransferDao transferDao;

    private static final Logger logger = Logger.getLogger(ThreeNewBoardController.class);

    /**
     * @RequestBody 返回的数据为对象
     * @RequestBody 可以接受map类型的参数
     */

    //密码加密测试接口
    @RequestMapping(value = "/encryption", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> responseIndex(@RequestBody Map<String, Object> paraMap) {
        String pwd = UtilMethod.md5Encryption(String.valueOf(paraMap.get("pwd")));
        logger.info(
                "****************************************************************************************\n"
                        +
                        "*                   调用加密测试接口，此接口仅供测试调取明文加密操作                                            *\n"
                        +
                        "****************************************************************************************");
        logger.info("明文：" + String.valueOf(paraMap.get("pwd")) + "加密加盐后为：" + pwd);
        paraMap.put("statusCode", "2000");
        paraMap.put("pwd", pwd);
        return paraMap;
    }

    /**
     * @param @param  user
     * @param @return 设定文件
     * @return Map<String,Object>    返回类型
     * @Title: addUser
     * @Description: TODO(注册)
     */
    @RequestMapping(value = "/register", method = RequestMethod.POST)
    @ResponseBody
    private Map<String, Object> addUser(@RequestBody User user) {
        logger.info("用户账号新增方法执行中...\n");
        logger.info("/register  Param:" + JSONObject.fromObject(user));
        Map<String, Object> map = new HashMap<>();
        if (userDao.checkPhone(user) != 0) {
            map.put("phone", user.getPhone());
            map.put("isRegister", false);
            map.put("promptMessage", "注册失败，手机号已绑定账号，请联系管理员或使用" + user.getPhone() + "绑定的账号登陆！");
            return ResponseMessage.isError(map);
        }
        // 生成随机账号
        String accountNumber = generateUsername();
        logger.info("生成随机账号：" + accountNumber);
        user.setAccountNumber(accountNumber);
        // 对密码进行加密
        user.setPassWord(UtilMethod.md5Encryption(user.getPassWord()));
        //进行普通用户类型赋予
        user.setAccountType(10010);
        //进行账户状态插入---正在审核
        user.setAccountStatus("60001");
        //进行数据插入
        userDao.registeredAll(user);
        map.put("accountNumber", accountNumber);
        map.put("isRegister", true);
        map.put("promptMessage", "注册成功，返回账号！");
        return ResponseMessage.isSuccess(map);
    }

    /**
     * @param @param  paraMap
     * @param @return 设定文件
     * @return Map<String,Object>    返回类型
     * @Title: retrieveStockCode
     * @Description: TODO(股票代码查询股票名称)
     */
    @RequestMapping(value = "/stockcode", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> retrieveStockCode(@RequestBody Map<String, Object> paraMap) {
        logger.info("/stockcode 	Param:" + paraMap.toString());
        StockCodeInformation scf = new StockCodeInformation();
        Map<String, Object> map = new HashMap<>();
        if ("".equals(paraMap.get("stockCode"))) {
            map.put("status", false);
            map.put("promptMessage", "请输入正确的股票代码！");
            return ResponseMessage.isError(map);
        }
        scf.setStockCode(Integer.valueOf(String.valueOf(paraMap.get("stockCode"))));
        scf = stockCodeDao.selectById(scf);
        if (scf != null) {
            map.put("stockCode", scf.getStockCode());
            map.put("stockCodeName", scf.getStockCodeName());
        } else {
            map.put("status", false);
            map.put("promptMessage", "股票代码有误，不在系统记录或不属于新三板！");
            return ResponseMessage.isError(map);
        }
        logger.info("查询股票代码成功！返回参数");
        return ResponseMessage.isSuccess(map);
    }


    /**
     * @param @param  user
     * @param @return 设定文件
     * @return Map<String,Object>   返回类型
     * @Title: addUser
     * @Description: TODO(管理员注册)
     */
    @RequestMapping(value = "/adminregister", method = RequestMethod.POST)
    @ResponseBody
    private Map<String, Object> addAdminUser(@RequestBody Map<String, Object> paraMap) {
        logger.info("管理员账号新增方法执行中...");
        logger.info("/adminregister  Param:" + paraMap.toString());
        Map<String, Object> map = new HashMap<>();
        User user = new User();
        User userToken = new User();
        user.setPhone(String.valueOf(paraMap.get("phone")));
        user.setUserName(String.valueOf(paraMap.get("userName")));
        userToken.setAccountNumber(String.valueOf(paraMap.get("accountNumber")));
        userToken.setTokenID(String.valueOf(paraMap.get("token")));
        if (!tokenVerification(userToken)) {
            map.put("status", false);
            map.put("promptMessage", "登陆状态验证失败，请重新登陆！");
            logger.info("验证token失败，状态为false,重新登陆！");
            return ResponseMessage.isError(map);
        }
        //管理员账户不允许进行自充值操作
        User userAdmin = new User();
        userAdmin.setAccountNumber(String.valueOf(paraMap.get("accountNumber")));
        userAdmin = userDao.selectCondition(userAdmin);
        if (userAdmin == null) {
            map.put("status", false);
            map.put("promptMessage", "管理员账号不存在！");
            logger.info("管理员账号不存在！");
            return ResponseMessage.isError(map);
        }
        if (userAdmin.getAccountType() != 10000) {
            map.put("status", false);
            map.put("promptMessage", "用户账号不允许调用此接口！");
            logger.info("用户账号不允许调用此接口！");
            return ResponseMessage.isError(map);
        }
        if (userDao.checkPhone(user) != 0) {
            map.put("phone", user.getPhone());
            map.put("isRegister", false);
            map.put("promptMessage", "注册失败，手机号已关联账号，请或使用" + user.getPhone() + "关联的账号登陆！");
            return ResponseMessage.isError(map);
        }
        // 生成随机账号
        String accountNumber = generateUsername();
        logger.info("生成随机管理员账号：" + accountNumber);
        user.setAccountNumber(accountNumber);
        // 对密码进行加密
        user.setPassWord(UtilMethod.md5Encryption(String.valueOf(paraMap.get("passWord"))));
        //进行普通用户类型赋予
        user.setAccountType(10000);
        // 赋予管理员账户无需进行审核
        user.setAccountStatus("60002");
        //进行数据插入
        userDao.registeredAll(user);
        map.put("accountNumber", accountNumber);
        map.put("isRegister", true);
        map.put("promptMessage", "注册成功，返回账号！");
        return ResponseMessage.isSuccess(map);
    }

    /**
     * @param @return 设定文件
     * @return String    返回类型
     * @Title: generateUsername
     * @Description: TODO(递归调用检查账号是否重复 ， 且返回不重复的账号)
     */
    private String generateUsername() {
        User user = new User();
        String uName = UtilMethod.randomCode();
        user.setUserName(uName);
        if (userDao.checkUsername(user) != 0) {
            generateUsername();
        }
        return uName;
    }

    /**
     * @param @param  paraMap
     * @param @return 设定文件
     * @return Map<String,Object>    返回类型
     * @Title: verificationPhone
     * @Description: TODO(验证手机号)
     */
    @RequestMapping(value = "/isnotphone", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> verificationPhone(@RequestBody Map<String, Object> paraMap) {
        logger.info("调取执行验证手机号方法，用于测试调用");
        logger.info("/isnotphone  Param:" + paraMap.toString());
        Map<String, Object> rMap = new HashMap<>();
        if (ValidateUtils.isMobile(String.valueOf(paraMap.get("phone")))) {
            rMap.put("isphone", ValidateUtils.isMobile(String.valueOf(paraMap.get("phone"))));
            logger.info("电话号码验证成功，返回true！");
            return ResponseMessage.isSuccess(rMap);
        } else {
            rMap.put("isphone", ValidateUtils.isMobile(String.valueOf(paraMap.get("phone"))));
            logger.info("电话号码验证失败，返回false！");
            return ResponseMessage.isError(rMap);
        }
    }

    /**
     * @param @param  paraMap
     * @param @return 设定文件
     * @return Map<String,Object>    返回类型
     * @Title: verificationIdCarde
     * @Description: TODO(验证身份证)
     */
    @RequestMapping(value = "/isnotidcard", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> verificationIdCarde(@RequestBody Map<String, Object> paraMap) {
        logger.info("/isnotidcard  Param:" + paraMap.toString());
        Map<String, Object> rMap = new HashMap<>();
        IdcardValidator iv = new IdcardValidator();
        if (iv.isValidatedAllIdcard(String.valueOf(paraMap.get("idCard")))) {
            rMap.put("isIdcard", iv.isValidatedAllIdcard(String.valueOf(paraMap.get("idCard"))));
            logger.info("身份证号码验证成功，返回true！");
            return ResponseMessage.isSuccess(rMap);
        } else {
            rMap.put("isIdcard", iv.isValidatedAllIdcard(String.valueOf(paraMap.get("idCard"))));
            logger.info("身份证号码验证失败，返回false！");
            return ResponseMessage.isError(rMap);
        }
    }

    /**
     * @param @param  user
     * @param @return 设定文件
     * @return Map<String,Object>    返回类型
     * @Title: userLogin
     * @Description: TODO(用户登陆)
     */
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> userLogin(@RequestBody Map<String, Object> paraMap) {
        logger.info("/login  Param:" + paraMap.toString());
        Map<String, Object> map = new HashMap<>();
        User user = new User();
        logger.info(String.valueOf(paraMap.get("accountNumber")));
        user.setAccountNumber(String.valueOf(paraMap.get("accountNumber")));
        user = userDao.selectByLogIn(user);
        if (user == null) {
            map.put("isLogin", false);
            map.put("promptMessage", "输入的账号不存在，请重新输入！");
            logger.info("输入的账号不存在，请重新输入！");
            return ResponseMessage.isError(map);
        }
        if (user.getAccountStatus() == null || "60001".equals(user.getAccountStatus()) && !"60002"
                .equals(user.getAccountStatus())) {
            map.put("isLogin", false);
            map.put("promptMessage", "您的账号正在审核，请耐心等待！");
            logger.info("输入的账号不存在，请重新输入！");
            return ResponseMessage.isError(map);
        }
        if ((UtilMethod.md5Encryption(String.valueOf(paraMap.get("passWord"))))
                .equals(user.getPassWord())) {
            if (tokenLogin(user)) {
                //进行管理员账号和普通账号类型反馈
                if (user.getAccountType() == 10000) {
                    map.put("isLogin", true);
                    map.put("userType", 10000);
                    map.put("token", user.getTokenID());
                    map.put("promptMessage", "验证成功，返回Token！");
                    logger.info("管理员密码验证成功，允许登陆，返回token，状态为true！");
                    return ResponseMessage.isSuccess(map);
                } else {
                    map.put("isLogin", true);
                    map.put("userType", 10010);
                    map.put("token", user.getTokenID());
                    map.put("promptMessage", "登录成功！");
                    logger.info("用户密码验证成功，允许登陆，返回token，状态为true！");
                    return ResponseMessage.isSuccess(map);
                }
            } else {
                map.put("isLogin", false);
                map.put("promptMessage", "Token获取失败，请重新登陆！");
                logger.info("密码验证成功，允许登陆，返回token失败，状态为false,失败类型手机号获取失败！");
                return ResponseMessage.isError(map);
            }
        } else {
            map.put("isLogin", false);
            map.put("promptMessage", "账号密码不匹配，请重新输入！");
            logger.info("密码验证失败，登陆失败！");
            return ResponseMessage.isError(map);
        }
    }

    /**
     * @param @param  paraMap
     * @param @return 设定文件
     * @return Map<String,Object>    返回类型
     * @Title: recharge
     * @Description: TODO(充值)
     */
    @RequestMapping(value = "/recharge", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> recharge(@RequestBody Map<String, Object> paraMap) {
        logger.info("/recharge  Param:" + paraMap.toString());
        Map<String, Object> map = new HashMap<>();
        User user = new User();
        CapitalFlow capitalFlow = new CapitalFlow();
        Transfer transfer = new Transfer();
        // 验证token
        // 检查登录状态
        User userToken = new User();
        userToken.setAccountNumber(String.valueOf(paraMap.get("accountNumber")));
        userToken.setTokenID(String.valueOf(paraMap.get("token")));
        if (!tokenVerification(userToken)) {
            map.put("status", false);
            map.put("promptMessage", "登陆状态验证失败，请重新登陆！");
            logger.info("验证token失败，状态为false,重新登陆！");
            return ResponseMessage.isError(map);
        }
        //管理员账户不允许进行自充值操作
        User userAdmin = new User();
        userAdmin.setAccountNumber(String.valueOf(paraMap.get("accountNumber")));
        userAdmin = userDao.selectCondition(userAdmin);
        if (userAdmin == null) {
            map.put("status", false);
            map.put("promptMessage", "管理员账号不存在！");
            logger.info("管理员账号不存在！");
            return ResponseMessage.isError(map);
        }
        if (userAdmin.getAccountType() != 10000) {
            map.put("status", false);
            map.put("promptMessage", "用户账号不允许调用此接口！");
            logger.info("用户账号不允许调用此接口！");
            return ResponseMessage.isError(map);
        }
        //具备基本权限,进行充值操作
        logger.info("具备基本权限，进行充值方法执行...");
        //Amount
        user.setAccountNumber(String.valueOf(paraMap.get("amountAccountNumber")));
        user = userDao.selectCondition(user);
        if (user == null) {
            map.put("status", false);
            map.put("promptMessage", "账号不存在，充值失败，请检查充值账号！");
            logger.info("账号不存在，充值失败，请检查充值账号！");
            return ResponseMessage.isError(map);
        }
        if (user.getAccountType() == 10000) {
            map.put("status", false);
            map.put("promptMessage", "账号为管理员账号，不允许进行充值操作！");
            logger.info("账号为管理员账号，不允许进行充值操作！");
            return ResponseMessage.isError(map);
        }
        User instUser = new User();
        instUser.setBalance(user.getBalance() + Double.valueOf(String.valueOf(paraMap.get("amount"))));
        instUser.setAccountNumber(user.getAccountNumber());
        logger.info(
                "执行充值方法,账号：" + instUser.getAccountNumber() + "的用户当前用户余额为：" + instUser.getBalance() + "元");
        logger.info("充值成功，生成订单！");
        //获取到充值的金额
        Double amount = Double.valueOf(String.valueOf(paraMap.get("amount")));
        capitalFlow.setCustomerCode(user.getAccountNumber());
        capitalFlow.setUserName(user.getUserName());
        capitalFlow.setFlowDirection(30001);
        capitalFlow.setAmount(amount);
        transfer.setSerialNumber(UtilMethod.getdingdan());
        //生成流水号
        capitalFlow.setSerialNumber(UtilMethod.getdingdan());
        capitalFlow.setOperatingTime(UtilMethod.unixString());
        capitalFlow.setStatusInformation("40002");
        capitalFlow.setTransactionType("20003");
        // 把充值的流水号关联到资金流水表中
        capitalFlow.setTradingFlow(transfer.getSerialNumber());
        capitalFlowDao.insertStreamAll(capitalFlow);
        userDao.updateAll(instUser);
        logger.info("生成订单完成，生成流水记录...");

        transfer.setAccountNumber(String.valueOf(paraMap.get("amountAccountNumber")));
        transfer.setFlow("20003");
        transfer.setAmount(Double.valueOf(String.valueOf(paraMap.get("amount"))));
        transfer.setOperatingTime(UtilMethod.unixString());
        transfer.setPhone(String.valueOf(paraMap.get("phone")));
        transfer.setUserName(String.valueOf(paraMap.get("userName")));
        transfer.setOperationAccount(String.valueOf(paraMap.get("accountNumber")));
        transfer.setOperator(userAdmin.getUserName());
        transferDao.insertTransfer(transfer);
        map.put("status", true);
        map.put("promptMessage", "账号：" + instUser.getAccountNumber() + "充值："
                + Double.valueOf(String.valueOf(paraMap.get("amount"))) + "元成功，当前用户余额为：" + instUser
                .getBalance() + "元");
        return ResponseMessage.isSuccess(map);
    }


    /**
     * @param @param  paraMap
     * @param @return 设定文件
     * @return Map<String,Object>    返回类型
     * @Title: buyingStock
     * @Description: TODO(买入卖出)
     */
    @RequestMapping(value = "/buyingstock", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> buyingStock(@RequestBody Map<String, Object> paraMap) {
        logger.info("/buyingstock  Param:" + paraMap.toString());
        Map<String, Object> map = new HashMap<>();
        User user = new User();
        CapitalFlow capitalFlow = new CapitalFlow();
        User installUser = new User();
        StockTrading stockTrading = new StockTrading();
        StockTrading stockOut = new StockTrading();
        paraMap.put("serialNumber", String.valueOf(paraMap.get("serialNumber")).toUpperCase());
        // 验证token
        // 检查登录状态
        User userToken = new User();
        userToken.setAccountNumber(String.valueOf(paraMap.get("accountNumber")));
        userToken.setTokenID(String.valueOf(paraMap.get("token")));
        if (!tokenVerification(userToken)) {
            map.put("status", false);
            map.put("promptMessage", "登陆状态验证失败，请重新登陆！");
            logger.info("验证token失败，状态为false,重新登陆！");
            return ResponseMessage.isError(map);
        }
        // 约定号验证
        try {
            if (!UtilMethod.isAppointment(paraMap)) {
                map.put("status", false);
                map.put("promptMessage", "约定号、对方席位、对方股东验证失败，请确认后重新输入！");
                logger.info("约定号、对方席位、对方股东验证失败，请确认后重新输入！");
                return ResponseMessage.isError(map);
            }
        } catch (Exception e) {
            map.put("status", false);
            map.put("promptMessage", "约定号、对方席位、对方股东验证失败，请确认后重新输入！");
            logger.info("约定号、对方席位、对方股东验证失败，请确认后重新输入！");
            return ResponseMessage.isError(map);
        }

        // 进行买入卖出分离操作，不同区别操作
        Integer seclarationType = Integer.valueOf(String.valueOf(paraMap.get("seclarationType")));
        if (seclarationType == 20001) {
            // 进行买入操作，扣除余额，进行余额变动生成，进行订单生成
            logger.info("进行买入操作，扣除余额，余额变动生成，进行订单生成...");
            // 进行余额判断是否满足买入条件
            user = userDao.selectByAmount(userToken);
            if (user.getBalance() >= (Double.valueOf(String.valueOf(paraMap.get("buyingAndSellingPrice")))
                    * Double.valueOf(String.valueOf(paraMap.get("quantity"))))) {
                logger.info("余额满足，进行交易生成...");
                installUser.setBalance(
                        user.getBalance() - (
                                Double.valueOf(String.valueOf(paraMap.get("buyingAndSellingPrice")))
                                        * Double.valueOf(String.valueOf(paraMap.get("quantity")))));
                installUser.setAccountNumber(user.getAccountNumber());
                // 进行余额扣除
                userDao.updateAll(installUser);
                logger.info("账户余额扣除成功,进行买入订单同步生成中...");
                // 进行订单同步生成
                stockTrading.setAccountNumber(user.getAccountNumber());
                stockTrading.setStockCode(Integer.valueOf(String.valueOf(paraMap.get("stockCode"))));
                stockTrading
                        .setBuyingAndSellingPrice(
                                Double.valueOf(String.valueOf(paraMap.get("buyingAndSellingPrice"))));
                stockTrading.setQuantity(Integer.valueOf(String.valueOf(paraMap.get("quantity"))));
                stockTrading.setSeclarationType("20001");
                // 生成流水号
                stockTrading.setSerialNumber(UtilMethod.getdingdan());
                stockTrading.setStockStatus("50001");
                stockTrading.setSeclarationTime(UtilMethod.unixString());
                stockTradingDao.buying(stockTrading);
                logger.info("买入订单生成成功,进行交易订单订单同步生成中...");
                Buyinformation buyinformation = new Buyinformation();
                buyinformation.setAccountNumber(user.getAccountNumber());
                buyinformation.setBuyRunningWaterNumber(UtilMethod.getdingdan());
                buyinformation.setQuantity(stockTrading.getQuantity());
                buyinformation.setBuyUnitPrice(stockTrading.getBuyingAndSellingPrice());
                buyinformation.setSerialNumber(stockTrading.getSerialNumber());
                buyinformation.setSeclarationTime(stockTrading.getSeclarationTime());
                buyinformation.setAccountNumber(stockTrading.getAccountNumber());
                buyinformation.setStockStatus("50003");
                buyinformation.setStockCode(String.valueOf(paraMap.get("stockCode")));
                buyinformationDao.insertBuyinformation(buyinformation);
                logger.info("交易订单生成成功,进行余额变动订单同步生成中...");
                capitalFlow.setCustomerCode(user.getAccountNumber());
                capitalFlow.setUserName(userToken.getUserName());
                capitalFlow.setFlowDirection(30002);
                capitalFlow.setAmount((Double.valueOf(String.valueOf(paraMap.get("buyingAndSellingPrice")))
                        * Double.valueOf(String.valueOf(paraMap.get("quantity")))));
                capitalFlow.setSerialNumber(stockTrading.getSerialNumber());
                capitalFlow.setOperatingTime(UtilMethod.unixString());
                capitalFlow.setStatusInformation("40002");
                capitalFlow.setTransactionType("20001");
                capitalFlow.setTradingFlow(UtilMethod.getdingdan());
                capitalFlow.setUserName(user.getUserName());
                capitalFlowDao.insertStreamAll(capitalFlow);
                logger.info("订单生成成功！");
                map.put("status", true);
                map.put("promptMessage",
                        "买入成功，本次交易账户扣除" + (Double.valueOf(String.valueOf(paraMap.get("buyingAndSellingPrice")))
                                * Double.valueOf(String.valueOf(paraMap.get("quantity")))) + "元。");
                logger.info(
                        "买入成功，本次交易账户扣除" + (Double.valueOf(String.valueOf(paraMap.get("buyingAndSellingPrice")))
                                * Double.valueOf(String.valueOf(paraMap.get("quantity")))) + "元。");
                return ResponseMessage.isSuccess(map);

            } else {
                map.put("status", false);
                map.put("promptMessage", "余额不足，不满足交易条件！");
                logger.info("余额不足，不满足交易条件！");
                return ResponseMessage.isError(map);
            }
        } else if (seclarationType == 20002) {
            // 必须进行订单查询是否满足卖出
            stockTrading.setSerialNumber(String.valueOf(paraMap.get("serialNumber")));
            stockTrading = stockTradingDao.selectId(stockTrading);
            if (stockTrading == null) {
                map.put("status", false);
                map.put("promptMessage", "交易失败，查询不到相关订单！");
                logger.info("交易失败，查询不到相关订单！");
                return ResponseMessage.isError(map);
            } else {
                // 进行订单数量是否满足交易数量
                if (stockTrading.getQuantity() < Integer.valueOf(String.valueOf(paraMap.get("quantity")))) {
                    map.put("status", false);
                    map.put("promptMessage", "交易失败，卖出数量不能超过订单数量！");
                    logger.info("交易失败，卖出数量不能超过订单数量！");
                    return ResponseMessage.isError(map);
                }
            }
            // 进行卖出操作，增加余额，进行余额变动生成，进行订单生成
            user = userDao.selectByAmount(userToken);
            logger.info("进行卖出操作，增加余额，余额变动生成，进行持仓信息修改，交易流水单生成 ...");
            installUser.setBalance(
                    user.getBalance() + (Double.valueOf(String.valueOf(paraMap.get("buyingAndSellingPrice")))
                            * Double.valueOf(String.valueOf(paraMap.get("quantity")))));
            // 进行持仓信息修改---只修改持仓数量
            stockOut.setSerialNumber(stockTrading.getSerialNumber());
            stockOut.setQuantity(
                    stockTrading.getQuantity() - Integer.valueOf(String.valueOf(paraMap.get("quantity"))));
            stockTradingDao.selling(stockOut);
            logger.info("持仓订单修改成功，卖出订单生成中...");
            Sellinformation sellinformation = new Sellinformation();
            sellinformation.setSellingSerialNumber(UtilMethod.getdingdan());
            sellinformation.setQuantity(Integer.valueOf(String.valueOf(paraMap.get("quantity"))));
            sellinformation
                    .setSellUnitPrice(Double.valueOf(String.valueOf(paraMap.get("buyingAndSellingPrice"))));
            sellinformation.setSerialNumber(stockTrading.getSerialNumber());
            sellinformation.setSellTime(UtilMethod.unixString());
            sellinformation.setAccountNumber(user.getAccountNumber());
            sellinformation.setStockStatus("50002");
            sellinformation.setStockCode(stockTrading.getStockCode());
            sellinformationDao.insertSellinformation(sellinformation);
            logger.info("卖出订单生成成功，进行余额变动...");
            installUser.setAccountNumber(user.getAccountNumber());
            userDao.updateAll(installUser);
            logger.info("账户余额变动成功,进行余额变动信息同步生成中...");
            capitalFlow.setCustomerCode(user.getAccountNumber());
            capitalFlow.setUserName(userToken.getUserName());
            capitalFlow.setFlowDirection(30001);
            capitalFlow.setAmount(Double.valueOf(String.valueOf(paraMap.get("buyingAndSellingPrice")))
                    * Double.valueOf(String.valueOf(paraMap.get("quantity"))));
            // 生成流水号
            capitalFlow.setSerialNumber(stockTrading.getSerialNumber());
            capitalFlow.setOperatingTime(UtilMethod.unixString());
            capitalFlow.setStatusInformation("40002");
            capitalFlow.setTransactionType("20002");
            capitalFlow.setUserName(user.getUserName());
            capitalFlow.setTradingFlow(UtilMethod.getdingdan());
            capitalFlowDao.insertStreamAll(capitalFlow);
            logger.info("订单生成成功！");
            map.put("status", true);
            map.put("promptMessage", "卖出成功！");
            map.put("promptMessage",
                    "卖出成功，本次交易账户新增" + (Double.valueOf(String.valueOf(paraMap.get("buyingAndSellingPrice")))
                            * Double.valueOf(String.valueOf(paraMap.get("quantity")))) + "元。");
            logger.info(
                    "卖出成功，本次交易账户新增" + (Double.valueOf(String.valueOf(paraMap.get("buyingAndSellingPrice")))
                            * Double.valueOf(String.valueOf(paraMap.get("quantity")))) + "元。");
            return ResponseMessage.isSuccess(map);
        } else {
            map.put("status", false);
            map.put("promptMessage", "交易类型未传入，交易失败！");
            logger.info("交易类型未传入，交易失败！");
            return ResponseMessage.isError(map);
        }
    }


    /**
     * @param @param  paraMap
     * @param @return 设定文件
     * @return Map<String,Object>    返回类型
     * @Title: queryAllserial
     * @Description: TODO(查询交易数据)
     */
    @RequestMapping(value = "/queryserial", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> queryAllserial(@RequestBody Map<String, Object> paraMap) {
        logger.info("/queryserial  Param:" + paraMap.toString());
        // 查询所有交易数据
        Map<String, Object> map = new HashMap<>();
        List<Map<String, Object>> list = new ArrayList<>();
        // 验证token
        // 检查登录状态
        User userToken = new User();
        userToken.setAccountNumber(String.valueOf(paraMap.get("accountNumber")));
        userToken.setTokenID(String.valueOf(paraMap.get("token")));
        if (!tokenVerification(userToken)) {
            map.put("status", false);
            map.put("promptMessage", "登陆状态验证失败，请重新登陆！");
            logger.info("验证token失败，状态为false,重新登陆！");
            return ResponseMessage.isError(map);
        }
        CapitalFlow capitalFlow = new CapitalFlow();
        capitalFlow.setCustomerCode(String.valueOf(paraMap.get("accountNumber")));
        list = capitalFlowDao.selectStreamAll(capitalFlow);
        for (Map<String, Object> map2 : list) {
            map2.put("flowDirection",
                    UtilMethod.typeStatusCode(String.valueOf(map2.get("flowDirection"))));
            map2.put("statusInformation",
                    UtilMethod.typeStatusCode(String.valueOf(map2.get("statusInformation"))));
            map2.put("transactionType",
                    UtilMethod.typeStatusCode(String.valueOf(map2.get("transactionType"))));
        }
        map.put("status", true);
        return ResponseMessage.isSuccess(list);
    }


    /**
     * @param @param  paraMap
     * @param @return 设定文件
     * @return Map<String,Object>    返回类型
     * @Title: queryAllOrders
     * @Description: TODO(股票交易订单查询)
     */
    @RequestMapping(value = "/queryorders", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> queryAllOrders(@RequestBody Map<String, Object> paraMap) {
        logger.info("/queryorders  Param:" + paraMap.toString());
        Map<String, Object> map = new HashMap<>();
        List<Map<String, Object>> list = new ArrayList<>();
        // 验证token
        // 检查登录状态
        User userToken = new User();
        userToken.setAccountNumber(String.valueOf(paraMap.get("accountNumber")));
        userToken.setTokenID(String.valueOf(paraMap.get("token")));
        if (!tokenVerification(userToken)) {
            map.put("status", false);
            map.put("promptMessage", "登陆状态验证失败，请重新登陆！");
            logger.info("验证token失败，状态为false,重新登陆！");
            return ResponseMessage.isError(map);
        }
        if ("50001".equals(paraMap.get("stockStatus"))) {
            StockTrading stockTrading = new StockTrading();
            stockTrading.setAccountNumber(String.valueOf(paraMap.get("accountNumber")));
            // 查询所有持仓信息
            list = stockTradingDao.selectAll(stockTrading);
            for (Map<String, Object> map2 : list) {
                map2.put("stockStatus", UtilMethod.typeStatusCode(String.valueOf(map2.get("stockStatus"))));
                map2.put("seclarationType",
                        UtilMethod.typeStatusCode(String.valueOf(map2.get("seclarationType"))));
            }
            map.put("status", true);
            return ResponseMessage.isSuccess(list);
        } else if ("50002".equals(paraMap.get("stockStatus"))) {
            // 查询所有卖出信息
            Sellinformation sellinformation = new Sellinformation();
            sellinformation.setAccountNumber(String.valueOf(paraMap.get("accountNumber")));
            list = sellinformationDao.selectSellinformationAll(sellinformation);
        } else if ("50003".equals(paraMap.get("stockStatus"))) {

            // 查询所有买入信息
            Buyinformation buyinformation = new Buyinformation();
            buyinformation.setAccountNumber(String.valueOf(paraMap.get("accountNumber")));
            list = buyinformationDao.selectBuyinformationAll(buyinformation);
        }
        // 进行查询到的数据迭代,输出给页面
        for (Map<String, Object> map2 : list) {
            map2.put("stockStatus", UtilMethod.typeStatusCode(String.valueOf(map2.get("stockStatus"))));
        }
        map.put("status", true);
        return ResponseMessage.isSuccess(list);
    }


    /**
     * @param @param  paraMap
     * @param @return 设定文件
     * @return Map<String,Object>    返回类型
     * @Title: getBankCardName
     * @Description: TODO(查询银行卡归属地)
     */
    @RequestMapping(value = "/bankcardname", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> getBankCardName(@RequestBody Map<String, Object> paraMap) {
        logger.info("/bankcardname  Param:" + paraMap.toString());
        Map<String, Object> map = new HashMap<>();
        if (paraMap.get("bankNumber") == "" || paraMap.get("bankNumber") == null) {
            map.put("status", false);
            map.put("promptMessage", "银行卡输入为空，请重新输入。");
            return ResponseMessage.isError(map);
        }
        GetCheckBankCard.getname(String.valueOf(paraMap.get("bankNumber")));
        logger.info("调用查询银行卡接口，卡号：" + String.valueOf(paraMap.get("bankNumber")) + "归属地为："
                + GetCheckBankCard.getname(String.valueOf(paraMap.get("bankNumber"))));
        map.put("bankNumber", paraMap.get("bankNumber"));
        map.put("bankName", GetCheckBankCard.getname(String.valueOf(paraMap.get("bankNumber"))));
        map.put("status", true);
        map.put("promptMessage", "查询成功！");
        return ResponseMessage.isSuccess(map);
    }

    /**
     * @param @param  paraMap
     * @param @return 设定文件
     * @return Map<String,Object>    返回类型
     * @Title: withdraw
     * @Description: TODO(提现 ， 转出)
     */
    @RequestMapping(value = "/transferout", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> withdraw(@RequestBody Map<String, Object> paraMap) {
        logger.info("/transferout  Param:" + paraMap.toString());
        Map<String, Object> map = new HashMap<>();
        User user = new User();
        CapitalFlow capitalFlow = new CapitalFlow();
        TransferInformation tfi = new TransferInformation();
        // 验证token
        // 检查登录状态
        User userToken = new User();
        userToken.setAccountNumber(String.valueOf(paraMap.get("accountNumber")));
        userToken.setTokenID(String.valueOf(paraMap.get("token")));
        if (!tokenVerification(userToken)) {
            map.put("status", false);
            map.put("promptMessage", "登陆状态验证失败，请重新登陆！");
            logger.info("验证token失败，状态为false,重新登陆！");
            return ResponseMessage.isError(map);
        }
        //判断余额是否足够，先扣除余额，再生成订单，插入信息
        userToken = userDao.selectCondition(userToken);
        user.setAccountNumber(userToken.getAccountNumber());
        //提现的金额
        Double amount = Double.valueOf(String.valueOf(paraMap.get("amount")));
        if (userToken.getBalance() >= amount) {
            user.setBalance(userToken.getBalance() - amount);
        } else {
            map.put("status", false);
            map.put("promptMessage", "转出失败，账户余额不足！");
            logger.info("提现失败，账户余额不足！");
            return ResponseMessage.isError(map);
        }
        //进行银行卡号验证
        if (!GetCheckBankCard.checkBankCard(String.valueOf(paraMap.get("bankNumber")))) {
            map.put("status", false);
            map.put("promptMessage", "转出失败，银行卡输入有误！");
            logger.info("转出失败，银行卡输入有误！");
            return ResponseMessage.isError(map);
        }
        //同步进行余额修改
        userDao.updateAll(user);
        logger.info("账户余额扣除成功,进行订单同步生成中...");
        capitalFlow.setCustomerCode(user.getAccountNumber());
        capitalFlow.setUserName(String.valueOf(paraMap.get("userName")));
        capitalFlow.setFlowDirection(30002);
        capitalFlow.setAmount(amount);
        //生成流水号
        capitalFlow.setSerialNumber(UtilMethod.getdingdan());
        capitalFlow.setOperatingTime(UtilMethod.unixString());
        capitalFlow.setStatusInformation("40001");
        capitalFlow.setTransactionType("20004");
        // 更新转出信息的流水号
        tfi.setSerialNumber(UtilMethod.getdingdan());
        // 资金流水表中关联转出信息流水号
        capitalFlow.setTradingFlow(tfi.getSerialNumber());
        capitalFlowDao.insertStreamAll(capitalFlow);
        logger.info("订单生成成功！转出信息进行入库登记中...");
        tfi.setCustomerCode(user.getAccountNumber());
        tfi.setUserName(String.valueOf(paraMap.get("userName")));
        tfi.setBankNumber(String.valueOf(paraMap.get("bankNumber")));
        tfi.setBankName(String.valueOf(paraMap.get("bankName")));
        tfi.setPhone(String.valueOf(paraMap.get("phone")));
        tfi.setAmount(amount);
        tfi.setOperatingTime(capitalFlow.getOperatingTime());
        transferInformationDao.insertAll(tfi);
        logger.info("转出信息入库登记成功！");
        map.put("status", true);
        map.put("promptMessage", "转出成功，两小时内到账！");
        logger.info("转出成功，两小时内到账！");
        return ResponseMessage.isSuccess(map);
    }

    /**
     * @param @param  user
     * @param @return 设定文件
     * @return Map<String,Object> 返回类型
     * @Title: queryAllUser
     * @Description: TODO(查询单个用户_管理员权限)
     */
    @RequestMapping(value = "/queryuser", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> queryUser(@RequestBody Map<String, Object> paraMap) {
        logger.info("/queryuser  Param:" + paraMap.toString());
        Map<String, Object> map = new HashMap<>();
        User user = new User();
        // 验证token
        // 检查登录状态
        User userToken = new User();
        userToken.setAccountNumber(String.valueOf(paraMap.get("accountNumber")));
        userToken.setTokenID(String.valueOf(paraMap.get("token")));
        if (!tokenVerification(userToken)) {
            map.put("status", false);
            map.put("promptMessage", "登陆状态验证失败，请重新登陆！");
            logger.info("验证token失败，状态为false,重新登陆！");
            return ResponseMessage.isError(map);
        }
        if (paraMap.get("number") == null || paraMap.get("number") == "") {
            //调用查询方法进行查询操作
            user.setAccountNumber(String.valueOf(paraMap.get("accountNumber")));
            user = userDao.selectByAmount(user);
            if (user == null) {
                map.put("status", false);
                map.put("promptMessage", "管理员账号不存在。");
                logger.info("管理员账号不存在。");
                return ResponseMessage.isError(map);
            }
            map.put("accountNumber", user.getAccountNumber());
            map.put("userName", user.getUserName());
            map.put("balance", user.getBalance());
            logger.info("查询到用户余额数据，返回前台！");
            return ResponseMessage.isSuccess(map);
        } else {
            logger.info("管理员转入页面调用查询用户信息。");
            user.setAccountNumber(String.valueOf(paraMap.get("number")));
            user = userDao.selectCondition(user);
            if (user == null) {
                map.put("status", false);
                map.put("promptMessage", "账号不存在，请重新输入。");
                logger.info("账号不存在。");
                return ResponseMessage.isError(map);
            }
            map.put("accountNumber", user.getAccountNumber());
            map.put("phone", user.getPhone());
            map.put("userName", user.getUserName());
            logger.info("数据查询成功，返回数据到前台。");
            return ResponseMessage.isSuccess(map);
        }

    }

    /**
     * @param @param  user
     * @param @return 设定文件
     * @return Map<String,Object> 返回类型
     * @Title: queryAllUser
     * @Description: TODO(查询全部用户_管理员权限)
     */
    @RequestMapping(value = "/queryalluser", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> queryAllUser(@RequestBody Map<String, Object> paraMap) {
        logger.info("/queryalluser  Param:" + paraMap.toString());
        Map<String, Object> map = new HashMap<>();
        User user = new User();
        // 验证token
        // 检查登录状态
        User userToken = new User();
        userToken.setAccountNumber(String.valueOf(paraMap.get("accountNumber")));
        userToken.setTokenID(String.valueOf(paraMap.get("token")));
        if (!tokenVerification(userToken)) {
            map.put("status", false);
            map.put("promptMessage", "登陆状态验证失败，请重新登陆！");
            logger.info("验证token失败，状态为false,重新登陆！");
            return ResponseMessage.isError(map);
        }
        user.setAccountNumber(String.valueOf(paraMap.get("accountNumber")));
        user = userDao.selectCondition(user);
        if (user == null) {
            map.put("status", false);
            map.put("promptMessage", "管理员账号不存在。");
            logger.info("管理员账号不存在。");
            return ResponseMessage.isError(map);
        }
        // 验证是否管理员账号
        if (user.getAccountType() == 10000) {
            // 具备管理员权限，进行数据查询展示
            List<User> list = new ArrayList<>();
            list = userDao.selectAll();
            List<Map<String, Object>> listMap = new ArrayList<>();
            for (User user2 : list) {
                LinkedHashMap<String, Object> userMap = new LinkedHashMap<String, Object>();
                userMap.put("accountNumber", user2.getAccountNumber());
                userMap.put("phone", user2.getPhone());
                userMap.put("userName", user2.getUserName());
                userMap.put("idCard", user2.getIdCard());
                userMap.put("balance", user2.getBalance());
                userMap.put("accountStatus",
                        UtilMethod.typeStatusCode(String.valueOf(user2.getAccountStatus())));
                listMap.add(userMap);
            }
            logger.info("数据查询成功，返回页面！");
            return ResponseMessage.isSuccess(listMap);
        } else {
            map.put("status", false);
            map.put("promptMessage", "账号不具备管理员权限！");
            logger.info("账号不具备管理员权限！");
            return ResponseMessage.isError(map);
        }
    }


    /**
     * @param @param  user
     * @param @return 设定文件
     * @return Map<String,Object> 返回类型
     * @Title: queryAllUser
     * @Description: TODO(查询全部管理员用户_管理员权限)
     */
    @RequestMapping(value = "/queryalladminuser", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> queryAllAdminUser(@RequestBody Map<String, Object> paraMap) {
        logger.info("/queryalladminuser  Param:" + paraMap.toString());
        Map<String, Object> map = new HashMap<>();
        User user = new User();
        // 验证token
        // 检查登录状态
        User userToken = new User();
        userToken.setAccountNumber(String.valueOf(paraMap.get("accountNumber")));
        userToken.setTokenID(String.valueOf(paraMap.get("token")));
        if (!tokenVerification(userToken)) {
            map.put("status", false);
            map.put("promptMessage", "登陆状态验证失败，请重新登陆！");
            logger.info("验证token失败，状态为false,重新登陆！");
            return ResponseMessage.isError(map);
        }
        user.setAccountNumber(String.valueOf(paraMap.get("accountNumber")));
        user = userDao.selectCondition(user);
        if (user == null) {
            map.put("status", false);
            map.put("promptMessage", "管理员账号不存在。");
            logger.info("管理员账号不存在。");
            return ResponseMessage.isError(map);
        }
        // 验证是否管理员账号
        if (user.getAccountType() == 10000) {
            // 具备管理员权限，进行数据查询展示
            List<User> list = new ArrayList<>();
            list = userDao.selectAdminAll();
            List<Map<String, Object>> listMap = new ArrayList<>();
            for (User user2 : list) {
                LinkedHashMap<String, Object> userMap = new LinkedHashMap<String, Object>();
                userMap.put("accountNumber", user2.getAccountNumber());
                userMap.put("phone", user2.getPhone());
                userMap.put("userName", user2.getUserName());
                listMap.add(userMap);
            }
            logger.info("数据查询成功，返回页面！");
            return ResponseMessage.isSuccess(listMap);
        } else {
            map.put("status", false);
            map.put("promptMessage", "账号不具备管理员权限！");
            logger.info("账号不具备管理员权限！");
            return ResponseMessage.isError(map);
        }
    }


    /**
     * @param @param  user
     * @param @return 设定文件
     * @return Map<String, Object>    返回类型
     * @Title: changePassword
     * @Description: TODO(修改用户密码)
     */
    @RequestMapping(value = "/changepassword", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> changePassword(@RequestBody Map<String, Object> paraMap) {
        logger.info("/changepassword  Param:" + paraMap.toString());
        Map<String, Object> map = new HashMap<>();
        User user = new User();
        // 验证token
        // 检查登录状态
        User userToken = new User();
        userToken.setAccountNumber(String.valueOf(paraMap.get("accountNumber")));
        userToken.setTokenID(String.valueOf(paraMap.get("token")));
        if (!tokenVerification(userToken)) {
            map.put("status", false);
            map.put("promptMessage", "登陆状态验证失败，请重新登陆！");
            logger.info("验证token失败，状态为false,重新登陆！");
            return ResponseMessage.isError(map);
        }
        //查询数据库存储密码
        user.setAccountNumber(String.valueOf(paraMap.get("accountNumber")));
        user = userDao.selectByLogIn(user);
        if ((UtilMethod.md5Encryption(String.valueOf(paraMap.get("passWord"))))
                .equals(user.getPassWord())) {
            //原密码比对成功
            user.setPassWord(UtilMethod.md5Encryption(String.valueOf(paraMap.get("newPassWord"))));
            userDao.updatePassword(user);
            //原密码比对成功，提示密码修改成功
            map.put("status", true);
            map.put("promptMessage", "修改密码成功！");
            logger.info("修改密码成功！");
            return ResponseMessage.isSuccess(map);
        } else {
            //原密码比对错误，提示原密码错误
            map.put("status", false);
            map.put("promptMessage", "原密码验证失败，请重新输入！");
            logger.info("原密码验证失败，请重新输入！");
            return ResponseMessage.isError(map);
        }
    }

    /**
     * @param @param  user
     * @param @return 设定文件
     * @return Map<String,Object>    返回类型
     * @Title: changePassword
     * @Description: TODO(管理员修改用户密码)
     */
    @RequestMapping(value = "/adminchpasswd", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> adminChangePassword(@RequestBody Map<String, Object> paraMap) {
        logger.info("/adminchpasswd  Param:" + paraMap.toString());
        Map<String, Object> map = new HashMap<>();
        User user = new User();
        // 验证token
        // 检查登录状态
        User userToken = new User();
        User adminUser = new User();
        userToken.setAccountNumber(String.valueOf(paraMap.get("accountNumber")));
        userToken.setTokenID(String.valueOf(paraMap.get("token")));
        if (!tokenVerification(userToken)) {
            map.put("status", false);
            map.put("promptMessage", "登陆状态验证失败，请重新登陆！");
            logger.info("验证token失败，状态为false,重新登陆！");
            return ResponseMessage.isError(map);
        }
        //查询数据库存储密码
        adminUser.setAccountNumber(String.valueOf(paraMap.get("accountNumber")));
        adminUser = userDao.selectCondition(adminUser);
        // 验证是否管理员账号
        if (adminUser == null) {
            map.put("status", false);
            map.put("promptMessage", "管理员账号不存在！");
            logger.info("管理员账号不存在！");
            return ResponseMessage.isError(map);
        }
        if (adminUser.getAccountType() != 10000) {
            map.put("status", false);
            map.put("promptMessage", "登陆账号不具备管理员权限，禁止调用！");
            logger.info("登陆账号不具备管理员权限，禁止调用！");
            return ResponseMessage.isError(map);
        }
        user.setAccountNumber(String.valueOf(paraMap.get("number")));
        user = userDao.selectCondition(adminUser);
        user.setPassWord(UtilMethod.md5Encryption(String.valueOf(paraMap.get("newPassWord"))));
        userDao.updatePassword(user);
        map.put("status", true);
        map.put("promptMessage", "修改密码成功！");
        logger.info("修改密码成功！");
        return ResponseMessage.isSuccess(map);
    }


    /**
     * @param @param  paraMap
     * @param @return 设定文件
     * @return Map<String,Object>    返回类型
     * @Title: queryTransferAll
     * @Description: TODO(查询全部转入数据)
     */
    @RequestMapping(value = "/querytransfer", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> queryTransferAll(@RequestBody Map<String, Object> paraMap) {
        logger.info("/querytransfer  Param:" + paraMap.toString());
        Map<String, Object> map = new HashMap<>();
        User user = new User();
        // 验证token
        // 检查登录状态
        User userToken = new User();
        userToken.setAccountNumber(String.valueOf(paraMap.get("accountNumber")));
        userToken.setTokenID(String.valueOf(paraMap.get("token")));
        if (!tokenVerification(userToken)) {
            map.put("status", false);
            map.put("promptMessage", "登陆状态验证失败，请重新登陆！");
            logger.info("验证token失败，状态为false,重新登陆！");
            return ResponseMessage.isError(map);
        }
        // 查询数据库存储用户信息
        user.setAccountNumber(String.valueOf(paraMap.get("accountNumber")));
        user = userDao.selectCondition(user);
        if (user == null) {
            map.put("status", false);
            map.put("promptMessage", "管理员账号不存在。");
            logger.info("管理员账号不存在。");
            return ResponseMessage.isError(map);
        }
        // 验证管理员
        if (!user.getAccountType().equals(10000)) {
            map.put("status", false);
            map.put("promptMessage", "非管理员账号，禁止调用查询！");
            logger.info("非管理员账号，禁止调用此接口！");
            return ResponseMessage.isError(map);
        }
        List<Map<String, Object>> list = new ArrayList<>();
        list = transferDao.selectTransfer();
        for (Map<String, Object> map2 : list) {
            map2.put("flow", UtilMethod.typeStatusCode(String.valueOf(map2.get("flow"))));
        }
        logger.info("查询数据成功，返回转入结果集");
        return ResponseMessage.isSuccess(list);
    }


    /**
     * @param @return 设定文件
     * @return Map<String,Object>    返回类型
     * @Title: userAccountReview
     * @Description: TODO(用户账号审核)
     */
    @RequestMapping(value = "/accountReview", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> userAccountReview(@RequestBody Map<String, Object> paraMap) {
        logger.info("/accountReview  Param:" + paraMap.toString());
        Map<String, Object> map = new HashMap<>();
        User user = new User();
        // 验证token
        // 检查登录状态
        User userToken = new User();
        userToken.setAccountNumber(String.valueOf(paraMap.get("accountNumber")));
        userToken.setTokenID(String.valueOf(paraMap.get("token")));
        if (!tokenVerification(userToken)) {
            map.put("status", false);
            map.put("promptMessage", "登陆状态验证失败，请重新登陆！");
            logger.info("验证token失败，状态为false,重新登陆！");
            return ResponseMessage.isError(map);
        }
        //进行管理员权限判断
        user.setAccountNumber(String.valueOf(paraMap.get("accountNumber")));
        user = userDao.selectCondition(user);
        if (user == null) {
            map.put("status", false);
            map.put("promptMessage", "管理员账号不存在。");
            logger.info("管理员账号不存在。");
            return ResponseMessage.isError(map);
        }
        if (user.getAccountType() != 10000) {
            map.put("status", false);
            map.put("promptMessage", "登陆账号不具备管理员权限，禁止调用！");
            logger.info("登陆账号不具备管理员权限，禁止调用！");
            return ResponseMessage.isError(map);
        }
        User instUser = new User();
        instUser.setAccountNumber(String.valueOf(paraMap.get("amountAccountNumber")));
        instUser.setAccountStatus("60002");
        User paramuser = new User();
        paramuser = userDao.selectCondition(instUser);
        if (paramuser == null) {
            map.put("status", false);
            map.put("promptMessage", "账号：" + String.valueOf(paraMap.get("amountAccountNumber"))
                    + "不存在，此接口不允许外部调用，请直接在页面点击审核按钮。");
            logger.info("账号：" + String.valueOf(paraMap.get("amountAccountNumber"))
                    + "不存在，此接口不允许外部调用，请直接在页面点击审核按钮。");
            return ResponseMessage.isError(map);
        }
        if (paramuser.getAccountType() == 10000) {
            map.put("status", false);
            map.put("promptMessage",
                    "账号：" + String.valueOf(paraMap.get("amountAccountNumber")) + "为管理员账号，不需要审核。");
            logger.info("账号：" + String.valueOf(paraMap.get("amountAccountNumber")) + "为管理员账号，不需要审核。");
            return ResponseMessage.isError(map);
        }
        if ("60002".equals(paramuser.getAccountStatus())) {
            map.put("status", false);
            map.put("promptMessage",
                    "账号：" + String.valueOf(paraMap.get("amountAccountNumber")) + "已审核完成，无需重复审核。");
            logger.info("账号：" + String.valueOf(paraMap.get("amountAccountNumber")) + "已审核完成，无需重复审核。");
            return ResponseMessage.isError(map);
        }
        userDao.updateAll(instUser);
        map.put("status", true);
        map.put("promptMessage",
                "账号：" + String.valueOf(paraMap.get("amountAccountNumber")) + "审核成功，请下发通知用户。");
        logger.info("账号：" + String.valueOf(paraMap.get("amountAccountNumber")) + "审核成功");
        return ResponseMessage.isSuccess(map);
    }

    /**
     * @param @param  paraMap
     * @param @return 设定文件
     * @return Map<String,Object>    返回类型
     * @Title: userTransferReview
     * @Description: TODO(转出审核)
     */
    @RequestMapping(value = "/transferreview", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> userTransferReview(@RequestBody Map<String, Object> paraMap) {
        logger.info("/transferreview  Param:" + paraMap.toString());
        Map<String, Object> map = new HashMap<>();
        User user = new User();
        // 验证token
        // 检查登录状态
        User userToken = new User();
        userToken.setAccountNumber(String.valueOf(paraMap.get("accountNumber")));
        userToken.setTokenID(String.valueOf(paraMap.get("token")));
        if (!tokenVerification(userToken)) {
            map.put("status", false);
            map.put("promptMessage", "登陆状态验证失败，请重新登陆！");
            logger.info("验证token失败，状态为false,重新登陆！");
            return ResponseMessage.isError(map);
        }
        //进行管理员权限判断
        user.setAccountNumber(String.valueOf(paraMap.get("accountNumber")));
        user = userDao.selectCondition(user);
        if (user == null) {
            map.put("status", false);
            map.put("promptMessage", "管理员账号不存在。");
            logger.info("管理员账号不存在。");
            return ResponseMessage.isError(map);
        }
        if (user.getAccountType() != 10000) {
            map.put("status", false);
            map.put("promptMessage", "登陆账号不具备管理员权限，禁止调用！");
            logger.info("登陆账号不具备管理员权限，禁止调用！");
            return ResponseMessage.isError(map);
        }
        CapitalFlow selectCapitalFlow = new CapitalFlow();
        selectCapitalFlow.setSerialNumber(String.valueOf(paraMap.get("serialNumber")));
        selectCapitalFlow = capitalFlowDao.selectStreamId(selectCapitalFlow);
        // 判断是否被更新
        if ("40002".equals(selectCapitalFlow.getStatusInformation())) {
            map.put("status", false);
            map.put("promptMessage", "此订单已被确认，请勿重复确认！");
            logger.info("此订单已被确认，请勿重复确认！");
            return ResponseMessage.isError(map);
        }
        CapitalFlow instCapitalFlow = new CapitalFlow();
        instCapitalFlow.setStatusInformation("40002");
        instCapitalFlow.setOperatingTime(UtilMethod.unixString());
        instCapitalFlow.setSerialNumber(String.valueOf(paraMap.get("serialNumber")));
        //进行转出状态修改
        capitalFlowDao.updateStream(instCapitalFlow);
        map.put("status", true);
        map.put("promptMessage", "转出订单已确认完成，用户信息已刷新。");
        logger.info("转出订单已确认完成，用户信息已刷新！");
        return ResponseMessage.isSuccess(map);
    }


    /**
     * @param @return 设定文件
     * @return Map<String,Object>    返回类型
     * @Title: checkUser
     * @Description: TODO(检查新用户注册)
     */
    @RequestMapping(value = "/checkuser", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> checkUserCount() {
        logger.info("调用新用户注册检测接口");
        Integer count = userDao.selectCheckCount();
        Map<String, Object> map = new HashMap<>();
        if (count != 0) {
            map.put("status", true);
            map.put("promptMessage", "核查到新用户注册，请管理员前往用户审核页面进行用户信息审核。");
            logger.info("核查到新用户注册，请管理员前往用户审核页面进行用户信息审核。");
            return ResponseMessage.isSuccess(map);
        }
        map.put("status", false);
        map.put("promptMessage", "未核查到注册的新用户。");
        logger.info("未核查到注册的新用户！");
        return ResponseMessage.isError(map);
    }


    /**
     * @param @return 设定文件
     * @return Map<String,Object>    返回类型
     * @Title: checkTransferCount
     * @Description: TODO(转出核查方法)
     */
    @RequestMapping(value = "/checkTransfer", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> checkTransferCount() {
        logger.info("转出提示接口");
        Integer count = capitalFlowDao.selectCheckCount();
        Map<String, Object> map = new HashMap<>();
        if (count != 0) {
            map.put("status", true);
            map.put("promptMessage", "核查到用户提交转出操作，请尽快前往转出页面核查转出信息，并转账给该用户，确认转账完成后对该笔订单进行转出确认操作。");
            logger.info("核查到用户提交转出操作");
            return ResponseMessage.isSuccess(map);
        }
        map.put("status", false);
        map.put("promptMessage", "未核查到用户提交转出操作。");
        logger.info("未核查到用户提交转出操作！");
        return ResponseMessage.isError(map);
    }

    /**
     * @param @param  paraMap
     * @param @return 设定文件
     * @return Map<String,Object>    返回类型
     * @Title: queryTransfer
     * @Description: TODO(查询所有转出数据 - - 管理员调用)
     */
    @RequestMapping(value = "/transferquery", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> queryTransfer(@RequestBody Map<String, Object> paraMap) {
        logger.info("/transferquery  Param:" + paraMap.toString());
        Map<String, Object> map = new HashMap<>();
        List<Map<String, Object>> list = new ArrayList<>();
        User user = new User();
        // 验证token
        // 检查登录状态
        User userToken = new User();
        userToken.setAccountNumber(String.valueOf(paraMap.get("accountNumber")));
        userToken.setTokenID(String.valueOf(paraMap.get("token")));
        if (!tokenVerification(userToken)) {
            map.put("status", false);
            map.put("promptMessage", "登陆状态验证失败，请重新登陆！");
            logger.info("验证token失败，状态为false,重新登陆！");
            return ResponseMessage.isError(map);
        }
        //进行管理员权限判断
        user.setAccountNumber(String.valueOf(paraMap.get("accountNumber")));
        user = userDao.selectCondition(user);
        if (user == null) {
            map.put("status", false);
            map.put("promptMessage", "管理员账号不存在。");
            logger.info("管理员账号不存在。");
            return ResponseMessage.isError(map);
        }
        if (user.getAccountType() != 10000) {
            map.put("status", false);
            map.put("promptMessage", "登陆账号不具备管理员权限，禁止调用！");
            logger.info("登陆账号不具备管理员权限，禁止调用！");
            return ResponseMessage.isError(map);
        }
        list = transferDao.selectTransfer();
        // 循环替换，进行状态码循环替换为内容
        for (Map<String, Object> map2 : list) {
            map2.put("flow", UtilMethod.typeStatusCode(String.valueOf(map2.get("flow"))));
        }
        return ResponseMessage.isSuccess(list);
    }


    /**
     * @param @param  paraMap
     * @param @return 设定文件
     * @return Map<String,Object>    返回类型
     * @Title: tranoutQuery
     * @Description: TODO(查询所有转出数据)
     */
    @RequestMapping(value = "/tranout", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> tranoutQuery(@RequestBody Map<String, Object> paraMap) {
        logger.info("/tranout  Param:" + paraMap.toString());
        Map<String, Object> map = new HashMap<>();
        List<Map<String, Object>> list = new ArrayList<>();
        User user = new User();
        // 验证token
        // 检查登录状态
        User userToken = new User();
        userToken.setAccountNumber(String.valueOf(paraMap.get("accountNumber")));
        userToken.setTokenID(String.valueOf(paraMap.get("token")));
        if (!tokenVerification(userToken)) {
            map.put("status", false);
            map.put("promptMessage", "登陆状态验证失败，请重新登陆！");
            logger.info("验证token失败，状态为false,重新登陆！");
            return ResponseMessage.isError(map);
        }
        //进行管理员权限判断
        user.setAccountNumber(String.valueOf(paraMap.get("accountNumber")));
        user = userDao.selectCondition(user);
        if (user == null) {
            map.put("status", false);
            map.put("promptMessage", "管理员账号不存在。");
            logger.info("管理员账号不存在。");
            return ResponseMessage.isError(map);
        }
        if (user.getAccountType() != 10000) {
            map.put("status", false);
            map.put("promptMessage", "登陆账号不具备管理员权限，禁止调用！");
            logger.info("登陆账号不具备管理员权限，禁止调用！");
            return ResponseMessage.isError(map);
        }
        list = capitalFlowDao.selectAll();
        for (Map<String, Object> map2 : list) {
            map2.put("flowDirection",
                    UtilMethod.typeStatusCode(String.valueOf(map2.get("flowDirection"))));
            map2.put("statusInformation",
                    UtilMethod.typeStatusCode(String.valueOf(map2.get("statusInformation"))));
            map2.put("transactionType",
                    UtilMethod.typeStatusCode(String.valueOf(map2.get("transactionType"))));
        }
        return ResponseMessage.isSuccess(list);
    }


    /**
     * @param @param  param
     * @param @return 设定文件
     * @return boolean    返回类型
     * @Title: tokenUUIDLogin
     * @Description: TODO(生成token)
     */
    public boolean tokenLogin(User param) {
        logger.info("/tokenLogin  Param:" + JSONObject.fromObject(param));
        // 验证帐号码是否为空
        if (param.getAccountNumber() != null && param.getAccountNumber().length() != 0) {
            // 获取UUID
            param.setTokenID(UtilMethod.uuidMd5Encryption());
            // 获取系统时间
            param.setTokenTime(UtilMethod.unixString());
            logger.info("token验证一致，加密后的token为：" + param.getTokenID());
            // 更新数据库的UUID和时间
            userDao.updateToken(param);
            return true;
        } else {
            // 账号为空
            logger.info("======账号为空，token无法验证======");
            return false;
        }
    }

    /**
     * @param @param  param
     * @param @return 设定文件
     * @return boolean    返回类型
     * @Title: tokenUUID
     * @Description: TODO(判断token是否有效 ， 进行存库 ， 比对 ， 更新)
     */
    public boolean tokenVerification(User param) {
        logger.info("/tokenVerification  Param:" + JSONObject.fromObject(param));
        User user = new User();
        User user1 = new User();
        // 验证帐号码是否为空
        if (param.getAccountNumber() != null) {
            user = userDao.selectCondition(param);
            if (user == null) {
                logger.info("======查询失败，账号不存在======");
                return false;
            }
            // 验证token是否一致
            if (param.getTokenID().equals(user.getTokenID())) {
                logger.info("token验证一致，加密后的token为：" + param.getTokenID());
                // 验证token的时间
                // 获取当前时间
                if (UtilMethod.unixString() - user.getTokenTime() <= ConstantParam.PARAM_THIRTY_MINUTES) {
                    // 更新数据库的token和时间
                    user1.setAccountNumber(param.getAccountNumber());
                    // token时间
                    user1.setTokenTime(UtilMethod.unixString());
                    userDao.updateToken(user1);
                    return true;
                } else {
                    logger.info("token已过期，请重新登录获取token，过期时间："
                            + ((UtilMethod.unixString() - user.getTokenTime())
                            - ConstantParam.PARAM_THIRTY_MINUTES));
                    return false;
                }
            } else {
                // token不一致
                logger.info("token验证不一致，存储的加密后的token为：" + user.getTokenID());
                logger.info("token验证不一致，传递的加密后的token为：" + param.getTokenID());
                return false;
            }
        } else {
            // 账号为空
            logger.info("======账号为空，token无法验证======");
            return false;
        }
    }

}
